package com.ruibang.glass.quality.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.quality.domain.req.DiscardDefectReq;
import com.ruibang.glass.quality.domain.req.EveryHourDiscardDefectReq;
import com.ruibang.glass.quality.entity.EveryHourHotEndDiscardDefect;
import com.ruibang.glass.quality.mapper.EveryHourHotEndDiscardDefectMapper;
import com.ruibang.glass.quality.service.EveryHourHotEndDiscardDefectService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-09-05  11:36
 * @Description: TODO
 * @Version: 1.0
 */

@Service
@Slf4j
public class EveryHourHotEndDiscardDefectServiceImpl extends ServiceImpl<EveryHourHotEndDiscardDefectMapper, EveryHourHotEndDiscardDefect> implements EveryHourHotEndDiscardDefectService {


    @Override
    public void deleteByDate(DiscardDefectReq defectReq) {
        baseMapper.deleteByDate(defectReq);
    }


    /**
     * @Description: 查询每小时判废缺陷数量及曲线
     * @version v1.0
     * @author songJinKang
     * @date 2023-09-06 14:50
     */
    @Override
    public ResultBody queryEveryHourColdDirectService(EveryHourDiscardDefectReq everydayDiscardDefectReq) {
        List<EveryHourHotEndDiscardDefect> everyHourDiscardDefectList = baseMapper.queryEveryHourColdDirect(everydayDiscardDefectReq);
        everyHourDiscardDefectList = everyHourDiscardDefectList.stream().sorted(Comparator.comparing(EveryHourHotEndDiscardDefect::getDiscardDate).reversed()).collect(Collectors.toList());
        return ResultBody.success(everyHourDiscardDefectList);
    }
}
